#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>

int main()
{
    int T, n, i, j, bool;
    int a[10][10];
    scanf("%d", &T);
    while (T--)
    {
        bool = 1;
        scanf("%d", &n);
        for (i = 0; i < n; i++)
        {
            for (j = 0; j < n; j++)
            {
                scanf("%d", &a[i][j]);
                if (j < i && a[i][j] != 0)
                {
                    bool = 0;
                }
            }
        }
        if (bool)
        {
            printf("YES\n");
        }
        else
        {
            printf("NO\n");
        }
    }
    return 0;
}